<?php

namespace App\Models;

use App\Models\Post;
use App\Models\DeviceGroup;
use App\Models\Sns;
use App\Models\DeviceGroupTask;
use Illuminate\Database\Eloquent\Model;

class Device extends Model
{
  protected $hidden = ['pivot'];

  public function deviceGroup()
  {
    return $this->belongsTo(DeviceGroup::class);
  }

  public function posts()
  {
    return $this->hasMany(Post::class);
  }

  public function postedSns()
  {
    return $this->belongsToMany(Sns::class, 'sns_device', 'device_id', 'sns_id');
  }

  public function isSns($device_id)
  {
    return $this->postedSns->contains($device_id);
  }

  public function finishTasks()
  {
    return $this->belongsToMany(DeviceGroupTask::class, 'task_device', 'device_id', 'device_group_task_id');
  }

  public function deviceDetailed()
  {
      return $this->hasMany(DeviceDetailedList::class);
  }
}
